package com.cqeec.util;

/**
 * 
 * @author HuaL
 * @description unicode转中文
 */
public class Ascii2Native {
	public static String ascii2Native(String str) {
		StringBuilder sb = new StringBuilder();
		int begin = 0;
		int index = str.indexOf("\\u");
		while (index != -1) {
			sb.append(str.substring(begin, index));
			sb.append(ascii2Char(str.substring(index, index + 6)));
			begin = index + 6;
			index = str.indexOf("\\u", begin);
		}
		sb.append(str.substring(begin));
		return sb.toString();
	}

	public static char ascii2Char(String str) {
		if (str.length() != 6) {
			throw new IllegalArgumentException("长度不足6位");
		}
		if (!"\\u".equals(str.substring(0, 2))) {
			throw new IllegalArgumentException("字符必须以 \"\\u\"开头.");
		}
		String tmp = str.substring(2, 4);
		int code = Integer.parseInt(tmp, 16) << 8;
		tmp = str.substring(4, 6);
		code += Integer.parseInt(tmp, 16);
		return (char) code;
	}
}
